package com.example.demo.Service;

import com.example.demo.entity.GetMsgVo;
import com.example.demo.entity.adminleng;
import com.example.demo.mapper.AdminlengMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

@Service
public class AdminlengService {

    @Autowired
    AdminlengMapper adminlengMapper;

    public String userGet(GetMsgVo msgVo)
    {
        try {
            return adminlengMapper.adminset(msgVo.getMsg());
        }catch (UncategorizedSQLException u)
        {
            System.out.println("sql异常，监听聊天记录为"+msgVo.toString());
        }
        return null;
    }
    public String userGet(String msgVo)
    {
        try {
            return adminlengMapper.adminset(msgVo);
        }catch (UncategorizedSQLException u)
        {
            System.out.println("sql异常，监听聊天记录为"+msgVo);
        }
        return null;
    }
    public String userCyc(GetMsgVo msgVo)
    {
        String code= "[CAT:nudge,target="+msgVo.getUserGet()+"]";
        msgVo.setUserGet(code);
        try {
            adminlengMapper.userset(msgVo);
        }
        catch (Exception e)
        {
            System.out.println("请求参数："+msgVo.toString());
            e.printStackTrace();
            return "添加失败";
        }
        return "设置成功";
    }
    public String userSet(GetMsgVo msgVo)
    {
        try {
            adminlengMapper.userset(msgVo);
        }catch (Exception e)
        {
            System.out.println("请求参数："+msgVo.toString());
            e.printStackTrace();
            return "设置失败，关键词已存在";
        }
        return "设置成功";
    }
    public String userDelete(GetMsgVo msgVo)
    {
        if(adminlengMapper.deleteset(msgVo.getUserSet())<1)
        {
            return "删除失败，关键词不存在";
        }
        return "删除成功";
    }
    public String userUpdate(GetMsgVo msgVo)
    {
        if(adminlengMapper.updateset(msgVo)<1)
        {
            return "关键词不存在";
        }
        return "更新成功";
    }
    public String userSelect(GetMsgVo msgVo)
    {
        adminleng admin=adminlengMapper.selectset(msgVo.getUserSet());

        return "关键词:" +admin.getUserset() +
                ",\n 返回词:" + admin.getReturnset()+
                ",\n设置人:" + admin.getUserid()+
                ",\n群名:" + admin.getGroupname()+
                ",\n群号:" + admin.getGroupid()+
                ",\n创建时间:" + admin.getTime();
    }
    public String rand(GetMsgVo msgVo)
    {
        String userid=msgVo.getUserId();
        Date date=new Date();
        SimpleDateFormat time=new SimpleDateFormat("yyyyMMdd");
        String all=time.format(date);
        long id= Long.parseLong(userid)+Long.parseLong(all);

        //获取最终随机种子 生成0-100的随机数
        Random R=new Random(id);
        id=R.nextInt(101);
        String cat="[CAT:at,code="+userid+"]您的今日人品是:"+id;
        if (id>=100)
        {
            return cat+"(金色传说)";
        }
        else if(id>=90)
        {
            return cat+"(传说)";
        }
        else if(id>=80)
        {
            return cat+"(史诗)";
        }
        else if(id>=70)
        {
            return cat+"(稀有)";
        }
        else if (id>=60)
        {
            return cat+"（良好）";
        }
        else if(id>=50)
        {
            return cat+"(普通)";
        }
        else if(id>=40)
        {
            return cat+"(不良)";
        }
        else if(id>=30)
        {
            return cat+"(小凶)";
        }
        else if(id>=20)
        {
            return cat+"(大凶)";
        }
        else if(id>=10)
        {
            return cat+"(惨)";
        }
        else
        {
            return cat+"(危)";
        }
    }

    //群消息撤回相应
    public String groupcall()
    {
        String[] arr={"撤回了什么？给我康康","说出来的话还能收出去？","恰独食?快给我康康",
                "不许撤回！再来点", "哇，照片是本人吗？", "照片里的小姐姐好好看",
                "小结巴看见了！撤回也没用", "他刚刚说自己要女装然后就撤回了", "?",
                "怀孕了就说嘛，大家一起想办法。撤回干什么呢"};
        Random r=new Random();
        int flag= r.nextInt(arr.length);
        return arr[flag];
    }

}
